package edu.ccut.saturn.studio.menuitem.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MenuItem implements IMenu, Comparable<MenuItem> {

	private MenuItem parent;

	private String parentId = "";

	private String id = "";

	private String label = "";

	private String path = "";

	private String order = "";

	private List<MenuItem> children = new ArrayList<MenuItem>();

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public List<MenuItem> getChildren() {
		if (children.size() > 1) {
			Collections.sort(children);
		}
		return children;
	}

	public void addChild(MenuItem child) {
		this.children.add(child);

		Collections.sort(children);
	}

	/**
	 * 当前节点个数等于子节点加上自己
	 * 
	 * @return
	 */
	public int size() {
		int size = 0;
		if (this.children != null) {
			for (MenuItem child : children) {
				size += child.size();
			}
		}

		return size + 1;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public MenuItem getParent() {
		return parent;
	}

	public void setParent(MenuItem parent) {
		this.parent = parent;
	}

	public int compareTo(MenuItem menuItem) {
		int order = Integer.parseInt(this.order);
		int menuItemOrder = Integer.parseInt(menuItem.order);

		return order - menuItemOrder;
	}
}
